/**
  ******************************************************************************
  * File Name          : gui_frmcalswrunning.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention: 进入此界面后,由界面切换实物状态机,此后由实物主程序接管界面切换,界面只负责置位相应
	* 						标志位,直到实物退出
  ******************************************************************************
  */
#include <stdio.h>
#include "dclcd.h"
#include "tskcfg.h"
#include "bsp.h"
#include "parameter.h"
#include <stdlib.h>
#include "measure.h"

static void ok(void);
static void keyret(void);
static void up(void);
static void load(uint8_t nowpage, uint8_t nowfocus);
static void update(uint8_t keyvalue);

static volatile uint8_t focus = 0;

const static GUI_FormKeysStru gui_calswrunning_keys = 
{
  .mute =   NULL,
  .power =  NULL,
  .keyt =   NULL,
  .set =    NULL,
  .home =   NULL,
  .menu =   NULL,
  .keyret = keyret,
  .enter =  NULL,
  .down =   up,
  .up =     up,
  .left =   NULL,
  .right =  NULL,
  .ok =     ok,  /* 由检验程序主动切换完成页面 ok键是退出用 */
  .volinc = NULL,
  .voldec = NULL,
  .key0 =   NULL,
  .key1 =   NULL,
  .key2 =   NULL,
  .key3 =   NULL,
  .key4 =   NULL,
  .key5 =   NULL,
  .key6 =   NULL,
  .key7 =   NULL,
  .key8 =   NULL,
  .key9 =   NULL,
};

const GUI_FormStru gui_from_calswrunning = 
{
  .load    = load,
  .update  = update,
  .keys    = &gui_calswrunning_keys,
  .refresh = &gui_mainmenu_refresh_time,
};

static void load(uint8_t nowpage, uint8_t nowfocus)
{
  dc_cmd_change_screen(15);

  /* 状态机切入实物校验 */
  meas_change_msm(MEAS_MAIN_STATE_MACHINE_CALSW, &gv);
}

static void update(uint8_t keyvalue)
{
  dc_update_calswrunning(0);
  
  dc_comp_showhide(15, 10, focus-0);
}

static void ok(void)
{
  if(focus != 0){
    gv.co.meas_ec.cal_shiwu_passed_key = 1;
  }else{
    gv.co.meas_ec.cal_shiwu_stop_key = 1;
  }
}

static void keyret(void)
{
  gv.co.meas_ec.cal_shiwu_stop_key = 1;
}

static void up(void)
{
  if(focus != 0){
    focus = 0;
  }else{
    focus = 1;
  }
}
